package com.sise.netty.粘包和粘包问题.固定协议代码.protocol;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * 协议编码器
 *
 * @author idea
 * @data 2019/4/17
 */
public class MyEncoder extends MessageToByteEncoder<MyProtocol> {


    @Override
    protected void encode(ChannelHandlerContext ctx, MyProtocol msg, ByteBuf out) {
        //定制协议的编码格式
        out.writeInt(msg.getHeadData());
        out.writeInt(msg.getContentLength());
        out.writeBytes(msg.getContent());
    }
}



